package cn.edu.nit.sys.service.impl;

import cn.edu.nit.sys.entity.Room;
import cn.edu.nit.sys.mapper.RoomMapper;
import cn.edu.nit.sys.service.RoomService;
import cn.edu.nit.sys.utils.R;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author xiaobai
 * @Date 2022/11/19 20:19
 * @Version 1.0.0
 */
@Service
public class RoomServiceImpl extends ServiceImpl<RoomMapper, Room> implements RoomService {

    @Override
    public R getRoomList(String siftName, Page<Room> page) {
        Page<Room> roomList = baseMapper.getRoomList(siftName, page);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("list", roomList.getRecords());
        jsonObject.put("total", roomList.getTotal());
        return R.ok(jsonObject);
    }

    @Override
    public R addRoom(Room room) {
        return baseMapper.insert(room) > 0 ? R.ok("添加成功") : R.error("添加失败");
    }
}
